/*
 *  FILE: 
 *  	file.h
 *
 *  DESCRIPTION:
 *  	Simple file/directory probing functions.  Along with the one string function: fileext().
 *      Also, some macros are defined.
 *
 *  FUNCTIONS:
 *      IS_READABLE()     -  Test to see if the file/directory is readable by the current user.
 *  	fileext()         -  A function capable of stripping the extension off of a filename.  It also
 *  	                     supports ".tar.gz" style extensions.
 *  	getfilesize()     -  Probe the size of any given file, using the filename.
 *  	                     32bit systems should define -D_LARGEFILE_SOURCE for support
 *  	                     for files larger than 4294967295 bytes (4 GB).
 *  	file_attributes() -  Simple function used to grab the attributes of a file stat.
 *  	is_file()         -  Test if filename is a file.
 *  	is_dir()          -  Test if filename is a directory.
 *
 *
 * Copyright (c) 2004-2006 Karlan Thomas Mitchell<karlanmitchell@gmail.com>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *         This product includes software developed by
           Karlan Thomas Mitchell<karlanmitchell@gmail.com>
 * 4. Neither Karlan Thomas Mitchell nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY KARLAN THOMAS MITCHELL AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
#ifndef SIMPLE_FILE_H
#define SIMPLE_FILE_H

#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <string.h>
#include "string.h"
#include <stdlib.h>

#include <dirent.h>
#ifdef WIN32
#else
#include <unistd.h>
#endif

#define IS_UEXE(file_name) (file_attributes(file_name) & S_IXUSR)
#define IS_GEXE(file_name) (file_attributes(file_name) & S_IXGRP)
#define IS_OEXE(file_name) (file_attributes(file_name) & S_IXOTH)

#define IS_UREADABLE(file_name) (file_attributes(file_name) & S_IRUSR)
#define IS_GREADABLE(file_name) (file_attributes(file_name) & S_IRGRP)
#define IS_OREADABLE(file_name) (file_attributes(file_name) & S_IROTH)




#ifndef WIN32
int IS_READABLE(char * file_name);
#endif

void fileext(char * file, char * ext, size_t extpntlen);
off_t getfilesize(char * filename);


#ifndef WIN32
mode_t file_attributes(char * tFile);
#endif
int display_file(char * file);
int is_file(char * file);
int is_dir(char * path);

#endif
